using System;

namespace Chambills.Present.Core
{
    /// <summary>
    /// Does not implement a finalizer, so it can be a base clase without penalty.
    /// If you need to ensure unmanaged resources are released, implment finalizer in concrete class
    /// <example>
    ///   
    ///    ~ManagedDisposable()
    ///    {
    ///        Dispose(false);
    ///    }
    /// 
    /// </example>
    /// </summary>
    public class ManagedDisposable : IDisposable
    {
        ///<summary>
        /// Performs application-defined tasks associated with freeing, releasing, or
        /// resetting managed resources.
        /// </summary>
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        /// <summary>
        /// Disposes the object.
        /// </summary>
        ///
        protected virtual void Dispose(bool disposing)
        {
            if (false == IsDisposed)
            {

                if (disposing)
                {
                    DisposeResources();
                }

                IsDisposed = true;
            }
        }

     

        protected virtual void DisposeResources()
        {
        }


        public bool IsDisposed { get; set; }

    }
}